<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">
                      <a-form-item label="评审表编号">
                        <a-input placeholder="请输入评审表编号" v-model="queryParam.code"></a-input>
                      </a-form-item>
                    </a-col>-->
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="制单日期">
              <j-date
                placeholder="请选择开始日期"
                class="query-group-cust"
                v-model="queryParam.createTime_begin"
              ></j-date>
              <span class="query-group-split-cust"></span>
              <j-date
                placeholder="请选择结束日期"
                class="query-group-cust"
                v-model="queryParam.createTime_end"
              ></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-if="activeKey=='cg'" @click="addNotice" type="primary" icon="plus">添加</a-button>
      <a-button v-if="activeKey=='cg'" @click="editReview" type="primary" icon="edit">修改定金</a-button>
      <a-button @click="lookReview" type="primary" icon="unordered-list">查看评审表</a-button>
      <a-button v-if="activeKey=='approved'"@click="tssm" type="primary" icon="credit-card">特殊说明</a-button>
      <a-button @click="returnReview" type="primary" icon="unordered-list">退回评审表</a-button>
      <a-button v-if="activeKey=='approved'"type="primary" icon="download" @click="handleExportXls('TSL国内订单')">导出</a-button>
      <a-button v-if="activeKey=='approved'"@click="openButton('isProduction','1')" type="primary" icon="check">生产开启</a-button>
      <a-button v-if="activeKey=='approved'"@click="openButton('isProduction','0')" type="danger" ghost icon="close">生产关闭</a-button>
      <a-button v-if="activeKey=='approved'"@click="openButton('isProcurement','1')" type="primary" icon="check">采购开启</a-button>
      <a-button v-if="activeKey=='approved'"@click="openButton('isProcurement','0')" type="danger" ghost icon="close">采购关闭</a-button>
      <a-button v-if="activeKey=='approved'"@click="openButton('isShipment','1')" type="primary" icon="check">发货开启</a-button>
      <a-button v-if="activeKey=='approved'"@click="openButton('isShipment','0')" type="danger" ghost icon="close">发货关闭</a-button>
    </div>
    <a-tabs v-model="activeKey" @change="handleChangeTab">
      <a-tab-pane key="cg" tab="未生成">
        <div>
          <a-table
            ref="procTable"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="table1.columns"
            :dataSource="table1.dataSource"
            :pagination="table1.ipagination"
            :loading="table1.loading"
            @change="handleTableChange1"
            :rowSelection="{ type:'radio', selectedRowKeys: table1.selectedRowKeys, onChange: onSelectChangeTab1 }"
          >
             <span slot="advancePayment" slot-scope="text, record">
               {{text!=null&&text>0?'是':'否'}}
             </span>

          </a-table>
        </div>
      </a-tab-pane>

      <a-tab-pane key="notGenerated" tab="暂存中" force-render>
        <div>
          <a-table
            ref="procTable"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="table2.columns"
            :dataSource="table2.dataSource"
            :pagination="table2.ipagination"
            :loading="table2.loading"
            @change="handleTableChange2"
            :rowSelection="{ type:'radio', selectedRowKeys: table2.selectedRowKeys, onChange: onSelectChangeTab2 }"
          >
            <span slot="advancePayment" slot-scope="text, record">
               {{text!=null&&text>0?'是':'否'}}
             </span>

            <span slot="action" slot-scope="text, record">
<!--              <a v-if="!record.actStatus" @click="handleEdit(record)">编辑</a>-->
              <a  @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical"></a-divider>
              <!--<a @click="relationAct(record)">关联流程</a> -->
              <act-apply-btn
                @success="loadNotGeneratedData"
                :data-id="record.id"
                :serviceName="serviceName"
                :variables="record"
              ></act-apply-btn>
              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                      <a>删除</a>
                    </a-popconfirm>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>

          </a-table>
        </div>
      </a-tab-pane>

      <a-tab-pane key="needEdit" tab="需修改" force-render>
        <div>
          <a-table
            ref="procTable"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="table3.columns"
            :dataSource="table3.dataSource"
            :pagination="table3.ipagination"
            :loading="table3.loading"
            @change="handleTableChange3"
            :rowSelection="{ type:'radio', selectedRowKeys: table3.selectedRowKeys, onChange: onSelectChangeTab3 }"
          >
            <span slot="advancePayment" slot-scope="text, record">
               {{text!=null&&text>0?'是':'否'}}
             </span>
            <span slot="action" slot-scope="text, record">
<!--              <a v-if="!record.actStatus" @click="handleEdit(record)">编辑</a>-->
              <a v-if="record.status < 0" @click="handleEdit(record)">编辑</a>
              <a-divider v-if="record.status < 0"  type="vertical"></a-divider>
              <act-apply-btn
                v-show="record.actStatus == '撤回'"
                @success="loadData"
                :data-id="record.id"
                :serviceName="serviceName"
                :variables="record"
              ></act-apply-btn>
              <a-popconfirm  v-if="record.actStatus != '撤回'" title="确定取消申请吗?" @confirm="() => handleStop(record)">
               <a href="javascript:;">取消申请</a>
              </a-popconfirm>
              <!--              <a-divider v-if="record.actStatus != '撤回'" type="vertical" />
                            <a v-if="record.actStatus !='撤回'" @click="handleProcess(record)">提交</a>-->
              <a-divider v-if="record.actStatus != '撤回'" type="vertical" />
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
               <a @click="handleDetail(record)">详情</a>
              <!--              <a-dropdown>
                              <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                              <a-menu slot="overlay">
                                <a-menu-item>
                                  <a @click="handleDetail(record)">详情</a>
                                </a-menu-item>
                                <a-menu-item>
                                  <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                                    <a>删除</a>
                                  </a-popconfirm>
                                </a-menu-item>
                              </a-menu>
                            </a-dropdown>-->
            </span>
          </a-table>
        </div>
      </a-tab-pane>

      <a-tab-pane key="approving" tab="审核中" force-render>
        <div>
          <a-table
            ref="procTable"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="table4.columns"
            :dataSource="table4.dataSource"
            :pagination="table4.ipagination"
            :loading="table4.loading"
            @change="handleTableChange4"
            :rowSelection="{ type:'radio', selectedRowKeys: table4.selectedRowKeys, onChange: onSelectChangeTab4 }"
          >
         <span slot="advancePayment" slot-scope="text, record">
               {{text!=null&&text>0?'是':'否'}}
             </span>

            <span slot="action" slot-scope="text, record">
<!--              <a v-if="!record.actStatus" @click="handleEdit(record)">编辑</a>
              <a-divider v-if="!record.actStatus"type="vertical"></a-divider>-->
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
              <a-divider type="vertical" />
              <a @click="handleDetail(record)">详情</a>
              <a-divider v-if="record.actStatus != '撤回'" type="vertical" />
              <a-popconfirm  v-if="record.actStatus != '撤回'" title="确定取消申请吗?" @confirm="() => handleStop(record)">
               <a href="javascript:;">取消申请</a>
              </a-popconfirm>
              <!--              <a-dropdown>
                              <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                              <a-menu slot="overlay">
                                <a-menu-item>
                                  <a @click="handleDetail(record)">详情</a>
                                </a-menu-item>
                              </a-menu>
                            </a-dropdown>-->
            </span>

          </a-table>
        </div>
      </a-tab-pane>

      <a-tab-pane key="approved" tab="已审批" force-render>
        <div>
          <a-table
            ref="procTable"
            size="middle"
            bordered
            rowKey="id"
            class="j-table-force-nowrap1"
            :scroll="{ x: true }"
            :columns="table5.columns"
            :dataSource="table5.dataSource"
            :pagination="table5.ipagination"
            :loading="table5.loading"
            @change="handleTableChange5"
            :rowSelection="{ type:'radio', selectedRowKeys: table5.selectedRowKeys, onChange: onSelectChangeTab5 }"
          >
          <span slot="advancePayment" slot-scope="text, record">
               {{text!=null&&text>0?'是':'否'}}
             </span>

            <span slot="action" slot-scope="text, record">
<!--              <a v-if="!record.actStatus" @click="handleEdit(record)">编辑</a>
              <a-divider v-if="!record.actStatus"type="vertical"></a-divider>-->
              <act-historic-detail-btn :data-id="record.id"></act-historic-detail-btn>
              <a-divider type="vertical" />
              <a @click="handleDetail(record)">详情</a>
              <!--              <a-dropdown>
                              <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                              <a-menu slot="overlay">
                                <a-menu-item>
                                  <a @click="handleDetail(record)">详情</a>
                                </a-menu-item>
                              </a-menu>
                            </a-dropdown>-->
            </span>
          </a-table>
        </div>
      </a-tab-pane>

    </a-tabs>
    <buss-tra-orders-modal ref="modalForm" @ok="modalFormOk"></buss-tra-orders-modal>

    <buss-contract-requirement-review-modal ref="reviewForm" @ok="modalFormOk"></buss-contract-requirement-review-modal>
    <buss-contract-review-des-modal ref="desModal" @ok="" />
  </a-card>
</template>

<script>
import {JeecgListMixin} from "@/mixins/JeecgListMixin";
import {mixinDevice} from "@/utils/mixin";
import {deleteAction, downFile, getAction,postAction} from "@api/manage";
import BussTraOrdersModal from './modules/BussTraOrdersModal'
import ActApplyBtn from '@views/flowable/components/ActApplyBtn.vue'
import ActCancelBtn from '@views/flowable/components/ActCancelBtn.vue'
import ActHandleBtn from '@views/flowable/components/ActHandleBtn.vue'
import ActHistoricDetailBtn from '@views/flowable/components/ActHistoricDetailBtn.vue'
import BussContractRequirementReviewModal from './modules/BussContractRequirementReviewModal'
import BussContractReviewDesModal from './modules/BussContractReviewDesModal'
import {stopProcess} from "@views/flowable/api/process";
import store from '@/store'
import {filterObj} from "@/utils/util";
export default {
  name: "BussTradeOrdersList",
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    BussTraOrdersModal,
    BussContractRequirementReviewModal,
    BussContractReviewDesModal,
    ActApplyBtn,
    ActCancelBtn,
    ActHandleBtn,
    ActHistoricDetailBtn,
  },
  data() {
    return {
      activeKey: 'cg',
      serviceName: 'crmTradeOrderService',
      table1: {
        selectedRowKeys: [],
        selectionRows: [],
        loading: false,
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '评审表编号',
            align: 'center',
            dataIndex: 'code',
            sorter: (a, b) => a.code.localeCompare(b.code, 'en'),

          },
          {
            title: '评审说明编号',
            align: 'center',
            dataIndex: 'pssmCode',
            sorter: (a, b) => a.code.localeCompare(b.pssmCode, 'en'),

          },

          {
            title: '订单编号',
            align: 'center',
            dataIndex: 'schedulingNumber',
            sorter: (a, b) => a.code.localeCompare(b.schedulingNumber, 'en'),
          },
          {
            title: '单据类型',
            align: 'center',
            dataIndex: 'documentType_dictText',
          },
          {
            title: '销售类型',
            align: 'center',
            dataIndex: 'salesType_dictText',
          },
          {
            title: '业务类型',
            align: 'center',
            dataIndex: 'contractBusinessType_dictText',
          },
          {
            title: '客户',
            align: 'center',
            dataIndex: 'customerId_dictText',
          },

          // {
          //   title: '柜数',
          //   align: 'center',
          //   dataIndex: 'cabinetCount',
          // },
          // {
          //   title: '流程状态',
          //   align: 'center',
          //   dataIndex: 'actStatus',
          // },
          // {
          //   title: '待处理节点',
          //   align: 'center',
          //   dataIndex: 'taskName',
          // },
          {
            title: '业务员',
            align: 'center',
            dataIndex: 'salesman_dictText',
          },
          {
            title: '定金',
            align: 'center',
            dataIndex: 'deposit',
          },
          {
            title: '定金是否到账',
            align: 'center',
            dataIndex: 'advancePayment',
            scopedSlots: { customRender: 'advancePayment' },
          },
          {
            title: '制单人',
            align: 'center',
            dataIndex: 'createBy_dictText',
          },
          {
            title: '制单部门',
            align: 'center',
            dataIndex: 'sysOrgCode_dictText',
          },
          {
            title: '制单时间',
            align: 'center',
            dataIndex: 'createTime',
            sorter: (a, b) => a.createTime.localeCompare(b.createTime, 'en'),
          },
        ],
        dataSource: [],
        isorter: {
          column: 'createTime',
          order: 'desc',
        },
        ipagination: {
          current: 1,
          pageSize: 20,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      table2: {
        selectedRowKeys: [],
        selectionRows: [],
        loading: false,
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '评审表编号',
            align: 'center',
            dataIndex: 'code',
            sorter: (a, b) => a.code.localeCompare(b.code, 'en'),

          },
          {
            title: '评审说明编号',
            align: 'center',
            dataIndex: 'pssmCode',
            sorter: (a, b) => a.code.localeCompare(b.pssmCode, 'en'),

          },

          {
            title: '订单编号',
            align: 'center',
            dataIndex: 'schedulingNumber',
            sorter: (a, b) => a.code.localeCompare(b.schedulingNumber, 'en'),
          },
          {
            title: '单据类型',
            align: 'center',
            dataIndex: 'documentType_dictText',
          },
          {
            title: '销售类型',
            align: 'center',
            dataIndex: 'salesType_dictText',
          },
          {
            title: '业务类型',
            align: 'center',
            dataIndex: 'contractBusinessType_dictText',
          },
          {
            title: '客户',
            align: 'center',
            dataIndex: 'customerName',
          },
          {
            title: '业务员',
            align: 'center',
            dataIndex: 'salesman_dictText',
          },
          {
            title: '定金',
            align: 'center',
            dataIndex: 'deposit',
          },
          {
            title: '定金是否到账',
            align: 'center',
            dataIndex: 'advancePayment',
            scopedSlots: { customRender: 'advancePayment' },
          },
          {
            title: '制单人',
            align: 'center',
            dataIndex: 'createBy_dictText',
          },
          {
            title: '制单部门',
            align: 'center',
            dataIndex: 'sysOrgCode_dictText',
          },
          {
            title: '制单时间',
            align: 'center',
            dataIndex: 'createTime',
            sorter: (a, b) => a.createTime.localeCompare(b.createTime, 'en'),
          },
          {
            title: '生产是否开启',
            align: 'center',
            dataIndex: 'isProduction_dictText',
          },
          {
            title: '采购是否开启',
            align: 'center',
            dataIndex: 'isProcurement_dictText',
          },
          {
            title: '发货是否开启',
            align: 'center',
            dataIndex: 'isShipment_dictText',
          },

          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 147,
            scopedSlots: { customRender: 'action' },
          },
        ],
        dataSource: [],
        isorter: {
          column: 'createTime',
          order: 'desc',
        },
        ipagination: {
          current: 1,
          pageSize: 20,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      table3: {
        selectedRowKeys: [],
        selectionRows: [],
        loading: false,
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '评审表编号',
            align: 'center',
            dataIndex: 'code',
            sorter: (a, b) => a.code.localeCompare(b.code, 'en'),

          },
          {
            title: '评审说明编号',
            align: 'center',
            dataIndex: 'pssmCode',
            sorter: (a, b) => a.code.localeCompare(b.pssmCode, 'en'),

          },

          {
            title: '订单编号',
            align: 'center',
            dataIndex: 'schedulingNumber',
            sorter: (a, b) => a.code.localeCompare(b.schedulingNumber, 'en'),
          },
          {
            title: '单据类型',
            align: 'center',
            dataIndex: 'documentType_dictText',
          },
          {
            title: '销售类型',
            align: 'center',
            dataIndex: 'salesType_dictText',
          },
          {
            title: '业务类型',
            align: 'center',
            dataIndex: 'contractBusinessType_dictText',
          },
          {
            title: '客户',
            align: 'center',
            dataIndex: 'customerName',
          },

          // {
          //   title: '柜数',
          //   align: 'center',
          //   dataIndex: 'cabinetCount',
          // },
          // {
          //   title: '流程状态',
          //   align: 'center',
          //   dataIndex: 'actStatus',
          // },
          // {
          //   title: '待处理节点',
          //   align: 'center',
          //   dataIndex: 'taskName',
          // },
          {
            title: '业务员',
            align: 'center',
            dataIndex: 'salesman_dictText',
          },
          {
            title: '定金',
            align: 'center',
            dataIndex: 'deposit',
          },
          {
            title: '定金是否到账',
            align: 'center',
            dataIndex: 'advancePayment',
            scopedSlots: { customRender: 'advancePayment' },
          },
          {
            title: '制单人',
            align: 'center',
            dataIndex: 'createBy_dictText',
          },
          {
            title: '制单部门',
            align: 'center',
            dataIndex: 'sysOrgCode_dictText',
          },
          {
            title: '制单时间',
            align: 'center',
            dataIndex: 'createTime',
            sorter: (a, b) => a.createTime.localeCompare(b.createTime, 'en'),
          },
          {
            title: '生产是否开启',
            align: 'center',
            dataIndex: 'isProduction_dictText',
          },
          {
            title: '采购是否开启',
            align: 'center',
            dataIndex: 'isProcurement_dictText',
          },
          {
            title: '发货是否开启',
            align: 'center',
            dataIndex: 'isShipment_dictText',
          },

          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 147,
            scopedSlots: { customRender: 'action' },
          },
        ],
        dataSource: [],
        isorter: {
          column: 'createTime',
          order: 'desc',
        },
        ipagination: {
          current: 1,
          pageSize: 20,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      table4: {
        selectedRowKeys: [],
        selectionRows: [],
        loading: false,
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '评审表编号',
            align: 'center',
            dataIndex: 'code',
            sorter: (a, b) => a.code.localeCompare(b.code, 'en'),

          },
          {
            title: '评审说明编号',
            align: 'center',
            dataIndex: 'pssmCode',
            sorter: (a, b) => a.code.localeCompare(b.pssmCode, 'en'),

          },

          {
            title: '订单编号',
            align: 'center',
            dataIndex: 'schedulingNumber',
            sorter: (a, b) => a.code.localeCompare(b.schedulingNumber, 'en'),
          },
          {
            title: '单据类型',
            align: 'center',
            dataIndex: 'documentType_dictText',
          },
          {
            title: '销售类型',
            align: 'center',
            dataIndex: 'salesType_dictText',
          },
          {
            title: '业务类型',
            align: 'center',
            dataIndex: 'contractBusinessType_dictText',
          },
          {
            title: '客户',
            align: 'center',
            dataIndex: 'customerName',
          },

          // {
          //   title: '柜数',
          //   align: 'center',
          //   dataIndex: 'cabinetCount',
          // },
          // {
          //   title: '流程状态',
          //   align: 'center',
          //   dataIndex: 'actStatus',
          // },
          // {
          //   title: '待处理节点',
          //   align: 'center',
          //   dataIndex: 'taskName',
          // },
          {
            title: '业务员',
            align: 'center',
            dataIndex: 'salesman_dictText',
          },
          {
            title: '定金',
            align: 'center',
            dataIndex: 'deposit',
          },
          {
            title: '定金是否到账',
            align: 'center',
            dataIndex: 'advancePayment',
            scopedSlots: { customRender: 'advancePayment' },
          },
          {
            title: '制单人',
            align: 'center',
            dataIndex: 'createBy_dictText',
          },
          {
            title: '制单部门',
            align: 'center',
            dataIndex: 'sysOrgCode_dictText',
          },
          {
            title: '制单时间',
            align: 'center',
            dataIndex: 'createTime',
            sorter: (a, b) => a.createTime.localeCompare(b.createTime, 'en'),
          },
          {
            title: '生产是否开启',
            align: 'center',
            dataIndex: 'isProduction_dictText',
          },
          {
            title: '采购是否开启',
            align: 'center',
            dataIndex: 'isProcurement_dictText',
          },
          {
            title: '发货是否开启',
            align: 'center',
            dataIndex: 'isShipment_dictText',
          },

          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 147,
            scopedSlots: { customRender: 'action' },
          },
        ],
        dataSource: [],
        isorter: {
          column: 'createTime',
          order: 'desc',
        },
        ipagination: {
          current: 1,
          pageSize: 20,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },
      table5: {
        selectedRowKeys: [],
        selectionRows: [],
        loading: false,
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            },
          },
          {
            title: '评审表编号',
            align: 'center',
            dataIndex: 'code',
            sorter: (a, b) => a.code.localeCompare(b.code, 'en'),

          },
          {
            title: '评审说明编号',
            align: 'center',
            dataIndex: 'pssmCode',
            sorter: (a, b) => a.code.localeCompare(b.pssmCode, 'en'),

          },

          {
            title: '订单编号',
            align: 'center',
            dataIndex: 'schedulingNumber',
            sorter: (a, b) => a.code.localeCompare(b.schedulingNumber, 'en'),
          },
          {
            title: '单据类型',
            align: 'center',
            dataIndex: 'documentType_dictText',
          },
          {
            title: '销售类型',
            align: 'center',
            dataIndex: 'salesType_dictText',
          },
          {
            title: '业务类型',
            align: 'center',
            dataIndex: 'contractBusinessType_dictText',
          },
          {
            title: '客户',
            align: 'center',
            dataIndex: 'customerName',
          },

          // {
          //   title: '柜数',
          //   align: 'center',
          //   dataIndex: 'cabinetCount',
          // },
          // {
          //   title: '流程状态',
          //   align: 'center',
          //   dataIndex: 'actStatus',
          // },
          // {
          //   title: '待处理节点',
          //   align: 'center',
          //   dataIndex: 'taskName',
          // },
          {
            title: '业务员',
            align: 'center',
            dataIndex: 'salesman_dictText',
          },
          {
            title: '定金',
            align: 'center',
            dataIndex: 'deposit',
          },
          {
            title: '定金是否到账',
            align: 'center',
            dataIndex: 'advancePayment',
            scopedSlots: { customRender: 'advancePayment' },
          },
          {
            title: '制单人',
            align: 'center',
            dataIndex: 'createBy_dictText',
          },
          {
            title: '制单部门',
            align: 'center',
            dataIndex: 'sysOrgCode_dictText',
          },
          {
            title: '制单时间',
            align: 'center',
            dataIndex: 'createTime',
            sorter: (a, b) => a.createTime.localeCompare(b.createTime, 'en'),
          },
          {
            title: '生产是否开启',
            align: 'center',
            dataIndex: 'isProduction_dictText',
          },
          {
            title: '采购是否开启',
            align: 'center',
            dataIndex: 'isProcurement_dictText',
          },
          {
            title: '发货是否开启',
            align: 'center',
            dataIndex: 'isShipment_dictText',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 147,
            scopedSlots: { customRender: 'action' },
          },
        ],
        dataSource: [],
        isorter: {
          column: 'createTime',
          order: 'desc',
        },
        ipagination: {
          current: 1,
          pageSize: 20,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0,
        },
      },

      url: {
        table1:{
          list: '/review/bussContractRequirementReview/noOrderGenerated',
        },
        list: '/review/crmTradeOrder/list',
        delete: '/review/crmTradeOrder/delete',
        exportXlsUrl: '/review/crmTradeOrder/exportXls',
        editMain: '/review/crmTradeOrder/editMain',
      }
    }
  },
  created() {
    this.queryParam = this.getQueryParams()
  },
  computed: {

  },
  methods: {
    handleStop(row) {
      const params = {
        instanceId: row.processInstanceId,
      }
      stopProcess(params).then((res) => {
        this.$message.success(res.message)
        this.handleChangeTab()
      })
    },
    handleDelete(id) {
      if (!this.url.delete) {
        this.$message.error("请设置url.delete属性!")
        return
      }
      var that = this;
      deleteAction(that.url.delete, {id: id}).then((res) => {
        if (res.success) {
          //重新计算分页问题
          that.reCalculatePage(1)
          that.$message.success(res.message);
          that.handleChangeTab();
        } else {
          that.$message.warning(res.message);
        }
      });
    },
    getQueryParams() {
      //获取查询条件
      let sqp = {}
      if (this.superQueryParams) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams)
        sqp['superQueryMatchType'] = this.superQueryMatchType
      }
      var param = Object.assign(sqp, this.queryParam, this.isorter, this.filters);
      param.field = this.getQueryField();
      param.pageNo = this.ipagination.current;
      param.pageSize = this.ipagination.pageSize;
      //P&G国外订单
      param.documentType = '4'
      return filterObj(param);
    },
    handleTableChange1(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      console.log(pagination)
      if (Object.keys(sorter).length > 0) {
        this.table1.isorter.column = sorter.field;
        this.table1.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      this.table1.ipagination = pagination;
      this.loadData();
    },
    handleTableChange2(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      console.log(pagination)
      if (Object.keys(sorter).length > 0) {
        this.table2.isorter.column = sorter.field;
        this.table2.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      this.table2.ipagination = pagination;
      this.loadNotGeneratedData();
    },
    handleTableChange3(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      console.log(pagination)
      if (Object.keys(sorter).length > 0) {
        this.table3.isorter.column = sorter.field;
        this.table3.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      this.table3.ipagination = pagination;
      this.loadNeedEditData();
    },
    handleTableChange4(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      console.log(pagination)
      if (Object.keys(sorter).length > 0) {
        this.table4.isorter.column = sorter.field;
        this.table4.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      this.table4.ipagination = pagination;
      this.loadApprovingData();
    },
    handleTableChange5(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      console.log(pagination)
      if (Object.keys(sorter).length > 0) {
        this.table5.isorter.column = sorter.field;
        this.table5.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      this.table5.ipagination = pagination;
      this.loadApprovedData();
    },
    handleDetail: function (record) {
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "详情";
      this.$refs.modalForm.disableSubmit = true;
      this.$refs.modalForm.disableSpecial = true
    },
    addNotice() {
      const rows = this.table1.selectionRows
      if (rows.length == 0) {
        this.$message.warn('请选择评审表！')
        return
      }
      //
      this.$refs.modalForm.add(rows[0])
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    },
    editReview(){
      const rows = this.table1.selectionRows
      if (rows.length == 0) {
        this.$message.warn('请选择评审表！')
        return
      }

      this.$refs.reviewForm.edit(rows[0])
      this.$refs.reviewForm.title = '修改'
      this.$refs.reviewForm.disableSubmit = false

    },
    returnReview(){
      let rows ={}
      switch (this.activeKey) {
        case 'cg':
          rows = this.table1.selectionRows
          if (rows.length == 0) {
            this.$message.warn('请选择评审表！')
            return
          }
          break
        case 'notGenerated':
          rows = this.table2.selectionRows
          if (rows.length == 0) {
            this.$message.warn('请选择订单！')
            return
          }
        case 'needEdit':
          rows = this.table3.selectionRows
          if (rows.length == 0) {
            this.$message.warn('请选择订单！')
            return
          }
        case 'approving':
          rows = this.table4.selectionRows
          if (rows.length == 0) {
            this.$message.warn('请选择订单！')
            return
          }
        case 'approved':
          rows = this.table5.selectionRows
          if (rows.length == 0) {
            this.$message.warn('请选择订单！')
            return
          }
      }
      let taskId=rows[0].taskId
      getAction("/review/bussContractRequirementReview/returnReview",{taskId:taskId,dataId:rows[0].id}).then(res => {
        if(res.success){
          this.$message.success(res.result.message)
          this.handleChangeTab()
        }
      })
    },
    lookReview(){
      let rows ={}
      let reviewId = '';
      switch (this.activeKey) {
        case 'cg':
          rows = this.table1.selectionRows
          if (rows.length == 0) {
            this.$message.warn('请选择评审表！')
            return
          }
          this.$refs.reviewForm.edit(rows[0])
          this.$refs.reviewForm.title = '详情'
          this.$refs.reviewForm.disableSubmit = true
          break
        case 'notGenerated':
          rows = this.table2.selectionRows
          if (rows.length == 0) {
            this.$message.warn('请选择订单！')
            return
          }
          reviewId = this.table2.selectionRows[0].reviewId;
        case 'needEdit':
          rows = this.table3.selectionRows
          if (rows.length == 0) {
            this.$message.warn('请选择订单！')
            return
          }
          reviewId = this.table3.selectionRows[0].reviewId;
        case 'approving':
          rows = this.table4.selectionRows
          if (rows.length == 0) {
            this.$message.warn('请选择订单！')
            return
          }
          reviewId = this.table4.selectionRows[0].reviewId;
        case 'approved':
          rows = this.table5.selectionRows
          if (rows.length == 0) {
            this.$message.warn('请选择订单！')
            return
          }
          reviewId = this.table5.selectionRows[0].reviewId;
      }
      getAction('/review/bussContractRequirementReview/getContractRequirementReview', { reviewId: reviewId }).then(res => {
        if (res.success) {
          this.$refs.reviewForm.edit(res.result)
          this.$refs.reviewForm.title = '详情'
          this.$refs.reviewForm.disableSubmit = true
        } else {
          this.$message.warning(res.message);
          return;
        }
      })


    },
    tssm(){
      const rows = this.table5.selectionRows
      if (rows.length == 0) {
        this.$message.warn('请选择订单！')
        return
      }

      this.$refs.modalForm.edit(rows[0])
      this.$refs.modalForm.title = '特殊说明'
      this.$refs.modalForm.disableSubmit = true
      this.$refs.modalForm.disableSpecial = false
    },
    openButton(record,code){
      if (this.table5.selectionRows.length == 0) {
        this.$message.warn('请选择订单！')
        return
      }
      const rows = this.table5.selectionRows[0]
      rows[record] = code
      postAction(this.url.editMain,rows).then((res)=>{
        if(res.code==200){
          this.$message.success(res.message);
          // that.$emit('ok');
        }else{
          this.$message.warning(res.message);
        }
      }).finally(() => {
        this.handleChangeTab()
      })

    },
    handleExportXls(fileName) {

      if (!fileName || typeof fileName != "string") {
        fileName = "导出文件"
      }
      let param = this.getQueryParams();
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(",")
      }
      param.status = 999
      downFile(this.url.exportXlsUrl, param).then((data) => {
        if (!data) {
          this.$message.warning("文件下载失败")
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], {type: 'application/vnd.ms-excel'}), fileName + '.xls')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], {type: 'application/vnd.ms-excel'}))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link); //下载完成移除元素
          window.URL.revokeObjectURL(url); //释放掉blob对象
        }
      })
    },

    modalFormOk() {
      // 新增/修改 成功时，重载列表
      this.searchQuery()
      //清空列表选中
      this.onClearSelected()
    },
    onClearSelected(){
      this.table1.selectedRowKeys=[];
      this.table2.selectedRowKeys=[];
      this.table3.selectedRowKeys=[];
      this.table4.selectedRowKeys=[];
      this.table5.selectedRowKeys=[];
    },
    searchQuery() {
      if(typeof this.beforeSearch === 'function'){
        let isreturn = this.beforeSearch()
        if(!isreturn){
          return;
        }
      }
      switch (this.activeKey) {
        case 'cg':
          this.loadData()
          break
        case 'notGenerated':
          this.loadNotGeneratedData()
          break
        case 'needEdit':
          this.loadNeedEditData()
          break
        case 'approving':
          this.loadApprovingData()
          break
        case 'approved':
          this.loadApprovedData()
          break
        default:
          break
      }
      //this.loadData(1);
      // 点击查询清空列表选中行
      // https://gitee.com/jeecg/jeecg-boot/issues/I4KTU1
    },

    onSelectChangeTab1(selectedRowKeys, selectionRows) {
      this.table1.selectedRowKeys = selectedRowKeys
      this.table1.selectionRows = selectionRows
    },
    onSelectChangeTab2(selectedRowKeys, selectionRows) {
      this.table2.selectedRowKeys = selectedRowKeys
      this.table2.selectionRows = selectionRows
    },
    onSelectChangeTab3(selectedRowKeys, selectionRows) {
      this.table3.selectedRowKeys = selectedRowKeys
      this.table3.selectionRows = selectionRows
    },
    onSelectChangeTab4(selectedRowKeys, selectionRows) {
      this.table4.selectedRowKeys = selectedRowKeys
      this.table4.selectionRows = selectionRows
    },
    onSelectChangeTab5(selectedRowKeys, selectionRows) {
      this.table5.selectedRowKeys = selectedRowKeys
      this.table5.selectionRows = selectionRows
    },

    handleChangeTab() {
      switch (this.activeKey) {
        case 'cg':
          this.loadData()
          break
        case 'notGenerated':
          this.loadNotGeneratedData()
          break
        case 'needEdit':
          this.loadNeedEditData()
          break
        case 'approving':
          this.loadApprovingData()
          break
        case 'approved':
          this.loadApprovedData()
          break
        default:
          break
      }
    },
    loadNotGeneratedData(){
      //未生成单据，status=-2
      this.queryParam = this.getQueryParams()
      this.queryParam.status = -2
      this.queryParam.field = this.getQueryField();
      this.queryParam.pageNo = this.table2.ipagination.current;
      this.queryParam.pageSize = this.table2.ipagination.pageSize;
      this.table2.loading = true
      getAction(this.url.list, this.queryParam)
        .then((res) => {
          if (res.success) {
            this.table2.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.table2.ipagination.total = res.result.total
            } else {
              this.table2.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }

        })
        .finally(() => {
          this.table2.loading = false
        })
    },
    loadNeedEditData(){
      //未生成单据，status=-2
      this.queryParam = this.getQueryParams()
      this.queryParam.status = -1
      this.queryParam.field = this.getQueryField();
      this.queryParam.pageNo = this.table3.ipagination.current;
      this.queryParam.pageSize = this.table3.ipagination.pageSize;
      this.table3.loading = true
      getAction(this.url.list, this.queryParam)
        .then((res) => {
          if (res.success) {
            this.table3.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.table3.ipagination.total = res.result.total
            } else {
              this.table3.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }

        })
        .finally(() => {
          this.table3.loading = false
        })
    },
    loadApprovingData(){
      //未生成单据，status=-2
      this.queryParam = this.getQueryParams()
      this.queryParam.status = 0
      this.queryParam.field = this.getQueryField();
      this.queryParam.pageNo = this.table4.ipagination.current;
      this.queryParam.pageSize = this.table4.ipagination.pageSize;
      this.table4.loading = true
      getAction(this.url.list, this.queryParam)
        .then((res) => {
          if (res.success) {
            this.table4.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.table4.ipagination.total = res.result.total
            } else {
              this.table4.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }

        })
        .finally(() => {
          this.table4.loading = false
        })
    },
    loadApprovedData() {
      //已审核单据，status=999
      this.queryParam = this.getQueryParams()
      this.queryParam.status = 999
      this.queryParam.field = this.getQueryField();
      this.queryParam.pageNo = this.table5.ipagination.current;
      this.queryParam.pageSize = this.table5.ipagination.pageSize;
      this.table5.loading = true

      getAction(this.url.list, this.queryParam)
        .then((res) => {
          console.log(res, '已审核单据')
          if (res.success) {
            this.table5.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.table5.ipagination.total = res.result.total
            } else {
              this.table5.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.table5.loading = false
        })
    },
    loadData(){
      this.queryParam = this.getQueryParams()
      this.queryParam.status =999
      this.queryParam.field = this.getQueryField();
      this.queryParam.pageNo = this.table1.ipagination.current;
      this.queryParam.pageSize = this.table1.ipagination.pageSize;
      this.table1.loading = true

      getAction(this.url.table1.list, this.queryParam).then((res) => {
        if (res.success) {
          //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.table1.dataSource = res.result.records || res.result;
          //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          if (res.result.total) {
            this.table1.ipagination.total = res.result.total
          } else {
            this.table1.ipagination.total = 0
          }
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.table1.loading = false
      })
    }
  }
}
</script>

<style scoped>

</style>